<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>

      <div style="padding: 5px 10px">
        <h3>分解项目标</h3>
        <el-collapse v-model="activeNames">
          <el-collapse-item title="监测项目标信息" name="1">
            <template slot="title">
              <div class="card-header collapse-header">
                <div class="head-title collapse-title">分解项目标信息</div>
              </div>
            </template>
            <table class="bs-table">
              <tr class="bs-table_row">
                <th class="bs-table_th">年度</th>
                <th class="bs-table_th">目标值</th>
                <th class="bs-table_th">目标内容</th>
              </tr>
              <tr class="bs-table_row" v-for="(li,k) in targetList" :key="k">
                <th class="bs-table_td">{{li.year}}年</th>
                <th class="bs-table_td">{{li.targetValue+li.targetValueUnit}}</th>
                <th class="bs-table_td">{{li.targetContent}}</th>
              </tr>
            </table>
            <div style="width:100%;text-align:center;padding-top:25px;font-size:20px;" v-if="targetList.length==0">
              暂无数据
            </div>
          </el-collapse-item>
        </el-collapse>
      </div>



      <div style="padding: 5px 10px">
        <div style="display:flex;justify-content: space-between;">
          <h3>进度信息</h3>
          <div class="form-submit">
            <el-button v-if='!$route.query.watch' type="primary" @click.stop="report()">报送</el-button>
            <el-button type="info" @click.stop="goBack()">关闭</el-button>
            <el-button type="success" @click.stop="exportProgressFile()">导出进度信息</el-button>
          </div>
        </div>

        <el-tabs tab-position="top" v-if="$route.query.type=='1'">
          <el-tab-pane :label="item.year+'年'" v-for="item in viewSubmitFormList" :key="item.year">
            <table class="bs-table">
              <tr class="bs-table_row">
                <th class="bs-table_th" width="60" v-if="$route.query.submitPeriod=='1'">时间</th>
                <th class="bs-table_th" width="120" v-if="$route.query.submitPeriod=='2'">时间</th>
                <th class="bs-table_th" width="100" v-if="$route.query.submitPeriod=='3'">时间</th>
                <th class="bs-table_th" width="160">地区名称</th>
                <!--<th class="bs-table_th" width="120">地区代码</th>-->
                <th class="bs-table_th" width="100">增加值</th>
                <th class="bs-table_th" width="100">累计增加值</th>
                <th class="bs-table_th" width="100">同比增速</th>
                <th class="bs-table_th" width="100">累计同比增速</th>
                <th class="bs-table_th" width="100">计量单位</th>
                <th class="bs-table_th">备注</th>
              </tr>
              <tr class="bs-table_row" v-for="elem in item.submitList" v-if="item.submitList" :key="elem.year">
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='1'">{{elem.year}}年</th>
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='2'">{{elem.year}}年第{{elem.quarter}}季度</th>
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='3'">{{elem.year}}年{{elem.month}}月</th>
                <th class="bs-table_td">
                  <el-button type="info" size="mini" @click="selectArea(elem.year,elem.quarter,elem.month,elem.period)"
                             plain>选择地区
                  </el-button>
                  <div>
                    {{elem.areaName}}
                  </div>
                  <!--<el-input type="textarea" :rows="2"-->
                            <!--class="textarea" autosize-->
                            <!--placeholder="请输入地区名称" v-model="elem.areaName"></el-input>-->
                </th>
                <!--<th class="bs-table_td">-->
                  <!--{{elem.areaCode}}-->
                  <!--&lt;!&ndash;<el-input type="textarea" :rows="2"&ndash;&gt;-->
                            <!--&lt;!&ndash;class="textarea" autosize&ndash;&gt;-->
                            <!--&lt;!&ndash;placeholder="请输入地区代码" v-model="elem.areaCode"></el-input>&ndash;&gt;-->
                <!--</th>-->
                <th class="bs-table_td">
                  <el-input placeholder="输入值" v-model="elem.value"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-input placeholder="输入值" v-model="elem.valueLj"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-input placeholder="输入值" v-model="elem.tbzs"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-input placeholder="输入值" v-model="elem.tbzsLj"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-select v-model="elem.measurement" placeholder="单位">

                    <el-option
                      v-for="item in measurementDIC"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>

                  </el-select>
                  <!--<el-input placeholder="" v-model="elem.measurement"></el-input>-->
                </th>
                <th class="bs-table_td">
                  <el-input type="textarea" :rows="2"
                            class="textarea" autosize
                            placeholder="输入备注内容" v-model="elem.remark"></el-input>
                </th>
              </tr>
            </table>
          </el-tab-pane>
        </el-tabs>
        <el-tabs tab-position="top" v-else>
          <el-tab-pane :label="item.year+'年'" v-for="item in viewSubmitFormList" :key="item.year">
            <table class="bs-table">
              <tr class="bs-table_row">
                <th class="bs-table_th" width="60" v-if="$route.query.submitPeriod=='1'">时间</th>
                <th class="bs-table_th" width="120" v-if="$route.query.submitPeriod=='2'">时间</th>
                <th class="bs-table_th" width="100" v-if="$route.query.submitPeriod=='3'">时间</th>
                <th class="bs-table_th" width="150">完成内容</th>
                <th class="bs-table_th" width="150">有关说明</th>
                <th class="bs-table_th" width="80">下步工作计划</th>
              </tr>
              <tr class="bs-table_row" v-for="elem in item.submitList" v-if="item.submitList" :key="elem.year">
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='1'">{{elem.year}}年</th>
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='2'">{{elem.year}}年第{{elem.quarter}}季度</th>
                <th class="bs-table_td" v-if="$route.query.submitPeriod=='3'">{{elem.year}}年{{elem.month}}月</th>
                <th class="bs-table_td">
                  <el-input type="textarea" :rows="2"
                            class="textarea" autosize
                            placeholder="请输入完成内容" v-model="elem.completeContent"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-input type="textarea" :rows="2"
                            class="textarea" autosize
                            placeholder="请输入有关说明" v-model="elem.havExplain"></el-input>
                </th>
                <th class="bs-table_td">
                  <el-input type="textarea" :rows="2"
                            class="textarea" autosize
                            placeholder="请输入下步工作计划" v-model="elem.nextStepPlan"></el-input>
                </th>
              </tr>
            </table>
          </el-tab-pane>
        </el-tabs>
      </div>

      <div style="padding: 5px 10px">
        <h3>历史进度信息</h3>
        <div v-for="hisItem in historyList" :key="hisItem.type">
          <el-tabs tab-position="top" v-if="$route.query.type=='1'">
            <el-tab-pane :label="item.year+'年'" v-for="item in hisItem.viewSubmitFormList" :key="item.year">
              <table class="bs-table">
                <tr class="bs-table_row">
                  <th class="bs-table_th" width="60" v-if="item.submitList[0].period=='1'">时间</th>
                  <th class="bs-table_th" width="120" v-if="item.submitList[0].period=='2'">时间</th>
                  <th class="bs-table_th" width="100" v-if="item.submitList[0].period=='3'">时间</th>
                  <th class="bs-table_th" width="160">地区名称</th>
                  <!--<th class="bs-table_th" width="120">地区代码</th>-->
                  <th class="bs-table_th" width="100">增加值</th>
                  <th class="bs-table_th" width="100">累计增加值</th>
                  <th class="bs-table_th" width="100">同比增速</th>
                  <th class="bs-table_th" width="100">累计同比增速</th>
                  <th class="bs-table_th" width="100">计量单位</th>
                  <th class="bs-table_th">备注</th>
                </tr>
                <tr class="bs-table_row" v-for="elem in item.submitList" v-if="item.submitList" :key="elem.year">
                  <th class="bs-table_td" v-if="elem.period=='1'">{{elem.year}}年</th>
                  <th class="bs-table_td" v-if="elem.period=='2'">{{elem.year}}年第{{elem.quarter}}季度</th>
                  <th class="bs-table_td" v-if="elem.period=='3'">{{elem.year}}年{{elem.month}}月</th>
                  <th class="bs-table_td">{{elem.areaName}}</th>
                  <!--<th class="bs-table_td">{{elem.areaCode}}</th>-->
                  <th class="bs-table_td">{{elem.value}}</th>
                  <th class="bs-table_td">{{elem.valueLj}}</th>
                  <th class="bs-table_td">{{elem.tbzs}}</th>
                  <th class="bs-table_td">{{elem.tbzsLj}}</th>
                  <th class="bs-table_td">{{elem.measurement}}</th>
                  <th class="bs-table_td">{{elem.remark}}</th>
                </tr>
              </table>
            </el-tab-pane>
          </el-tabs>
          <el-tabs tab-position="top" v-else>
            <el-tab-pane :label="item.year+'年'" v-for="item in hisItem.viewSubmitFormList" :key="item.year">
              <table class="bs-table">
                <tr class="bs-table_row">
                  <th class="bs-table_th" width="60" v-if="item.submitList[0].period=='1'">时间</th>
                  <th class="bs-table_th" width="120" v-if="item.submitList[0].period=='2'">时间</th>
                  <th class="bs-table_th" width="100" v-if="item.submitList[0].period=='3'">时间</th>
                  <th class="bs-table_th" width="150">完成内容</th>
                  <th class="bs-table_th" width="150">有关说明</th>
                  <th class="bs-table_th" width="80">下步工作计划</th>
                </tr>
                <tr class="bs-table_row" v-for="elem in item.submitList" v-if="item.submitList" :key="elem.year">
                  <th class="bs-table_td" v-if="elem.period=='1'">{{elem.year}}年</th>
                  <th class="bs-table_td" v-if="elem.period=='2'">{{elem.year}}年第{{elem.quarter}}季度</th>
                  <th class="bs-table_td" v-if="elem.period=='3'">{{elem.year}}年{{elem.month}}月</th>
                  <th class="bs-table_td">{{elem.completeContent}}</th>
                  <th class="bs-table_td">{{elem.havExplain}}</th>
                  <th class="bs-table_td">{{elem.nextStepPlan}}</th>
                </tr>
              </table>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>

      <div style="padding: 5px 10px">
        <h3>分解项信息</h3>
        <table class="bs-table">
          <tr class="bs-table_row">
            <th class="bs-table_th" style="width: 200px">规划名称</th>
            <td class="bs-table_td" colspan="3">{{detailList.planningTitle}}</td>
          </tr>
          <tr class="bs-table_row" v-if="detailList.type==1">
            <th class="bs-table_th">分解项名称</th>
            <td class="bs-table_td">{{detailList.itemName}}</td>
            <th class="bs-table_th">属性</th>
            <td class="bs-table_td"> {{detailList.attribute==0?'预期性':detailList.attribute==1?'约束性':''}}</td>
          </tr>
          <tr class="bs-table_row" v-else>
            <th class="bs-table_th">分解项名称</th>
            <td class="bs-table_td" colspan="3">{{detailList.itemName}}</td>
          </tr>

          <tr class="bs-table_row">
            <th class="bs-table_th" style="width: 200px">时间类型</th>
            <td class="bs-table_td">
              {{detailList.submitPeriod=='1'?'年报':detailList.submitPeriod=='2'?'季报':detailList.submitPeriod=='3'?'月报':''}}
            </td>
            <th class="bs-table_th">分解项类别</th>
            <td class="bs-table_td">
              {{detailList.type=='1'?'指标':detailList.type=='2'?'任务':detailList.type=='3'?'项目':''}}
            </td>
          </tr>
          <tr class="bs-table_row">
            <th class="bs-table_th">牵头部门</th>
            <td class="bs-table_td">{{detailList.leadDeptName}}</td>
            <th class="bs-table_th">配合部门</th>
            <td class="bs-table_td">{{detailList.cooDeptNameList|filter}}</td>
          </tr>
          <tr class="bs-table_row" v-if="detailList.type!=2">
            <th class="bs-table_th">起止日期</th>
            <td class="bs-table_td" v-if="detailList.startDate&detailList.endDate">
              {{detailList.startDate+'-'+detailList.endDate}}
            </td>
            <td class="bs-table_td" v-else>无</td>
            <th class="bs-table_th">总目标</th>
            <td class="bs-table_td">{{detailList.totalTarget+detailList.totalTargetUnit}}</td>
          </tr>


          <tr class="bs-table_row" v-if="detailList.type==1">
            <th class="bs-table_th">基数</th>
            <td class="bs-table_td">{{detailList.base}}</td>
            <th class="bs-table_th">年均增长</th>
            <td class="bs-table_td">{{detailList.yearAverageRise}}</td>
          </tr>
          <tr class="bs-table_row" v-if="detailList.type==1">
            <th class="bs-table_th">是否可量化</th>
            <td class="bs-table_td">{{detailList.quantifiable?'可量化':'不可量化'}}</td>
            <th class="bs-table_th">分类</th>
            <td class="bs-table_td">
              {{detailList.classify==1?'经济发展':detailList.classify==2?'创新驱动':detailList.classify==3?'民生福祉':detailList.classify==4?'资源环境':''}}
            </td>
          </tr>
          <tr class="bs-table_row" v-else-if="detailList.type==3">
            <th class="bs-table_th">是否可量化</th>
            <td class="bs-table_td" colspan="3">{{detailList.quantifiable?'可量化':'不可量化'}}</td>
          </tr>
          <tr class="bs-table_row">
            <th class="bs-table_th">分解项内容</th>
            <td class="bs-table_td" colspan="3">{{detailList.description}}</td>
          </tr>

        </table>
      </div>

      <!--选择地区-->
      <area-select :visible="areaSelectVisible" @getAreaInfo="getAreaInfo" @cancel="cancelGetArea"></area-select>
    </div>
  </basic-container>
</template>

<script>
  import { PROJECT_DIC } from "@/const/dict";
  import {pimWorkingItemRules} from "@/const/infoRules";
  import {
    decomposeItemDetail,
    workingItemTargetList,
    submitTargetProgress,
    submitTaskProgress,
    submitProjectProgress,
    getOldTargetList,
    getOldTaskList,
    getOldProjectList,
    editTargetProgress,
    editTaskProgress,
    editProjectProgress,
    getReportProgressHisProject,
    getReportProgressHisTask,
    getReportProgressHisTarget,
    exportProgressFile,
  } from "@/api/pim/pim";
  import {mapGetters} from "vuex";

  export default {
    name: "editProgressPeriodChangedEdit",
    created() {
      this.getDecomposeItemDetail();
      this.getWorkingItemTargetList();
      this.putSubmitFormList();
      this.putHistory();
    },
    filters: {
      filter(e) {
        if (e) {
          let a = '';
          for (let li of e) {
            a = a + li
          }
          return a
        }
      }
    },
    computed: {
      ...mapGetters([
        "deptInfo"
      ])
    },
    data() {
      return {
        measurementDIC: PROJECT_DIC.MEASUREMENT,
        headerData: {
          title: '进度信息'
        },
        activeNames: ['1'],
        detailList: {},
        targetList: [],
        targetForm: {    //指标表单要提交的字段
          id: null,
          ditemId: null,  //分解项ID
          period: this.$route.query.submitPeriod,   //周期类型
          year: null,
          month: null,
          quarter: null,
          areaCode: null,
          areaName: null,
          value: null,
          valueLj: null,
          tbzs: null,
          tbzsLj: null,
          measurement: null,
          remark: null,
        },
        taskForm: {    //任务和项目表单要提交的字段
          id: null,
          ditemId: null,  //分解项ID
          period: this.$route.query.submitPeriod,   //周期类型
          year: null,
          month: null,
          quarter: null,
          completeContent: null,
          havExplain: null,
          nextStepPlan: null,
        },
        submitFormList: [],//提交的表单数组
        viewSubmitFormList: [],//展示用的表单数组
        historyList: [],//展示历史的上报的进度
        areaSelectVisible: false,
        yearTemp: '',
        quarterTemp: '',
        monthTemp: '',
        periodTemp: '',

      }
    },
    methods: {
      getDecomposeItemDetail() {
        decomposeItemDetail(this.$route.query.id).then(response => {
          if (response.data.code == 0) {
            this.detailList = response.data.data
          }
        })
      },
      getWorkingItemTargetList() {
        workingItemTargetList(this.$route.query.id).then(response => {
          if (response.data.code == 0) {
            this.targetList = response.data.data
          }
        })
      },
      report() {
        this.$confirm("确定报送吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(async () => {
          let formList = await this.handleFormList();
          if (this.$route.query.type == '1') { //指标
            let submitForm = Object.assign({
              pimProgressTargetDTOList: [],
            });
            submitForm.pimProgressTargetDTOList = formList;
            editTargetProgress(submitForm).then(response => {
              if (response.data.code == '0') {
                this.$message({
                  message: '报送成功！',
                  type: 'success'
                });
                this.goBack();
              }
            })
          } else if (this.$route.query.type == '2') { //任务
            let submitForm = Object.assign({
              pimProgressTaskDTOList: [],
            });
            submitForm.pimProgressTaskDTOList = formList;
            editTaskProgress(submitForm).then(response => {
              if (response.data.code == '0') {
                this.$message({
                  message: '报送成功！',
                  type: 'success'
                });
                this.goBack();
              }
            })
          } else if (this.$route.query.type == '3') { //项目
            let submitForm = Object.assign({
              pimProgressProjectDTOList: [],
            });
            submitForm.pimProgressProjectDTOList = formList;
            editProjectProgress(submitForm).then(response => {
              if (response.data.code == '0') {
                this.$message({
                  message: '报送成功！',
                  type: 'success'
                });
                this.goBack();
              }
            })
          }

        })
      },
      handleFormList() {
        if (this.$route.query.submitPeriod == '1') {  //年报
          for (let submitItem in this.submitFormList) {
            for (let viewItem in this.viewSubmitFormList) {
              if (this.submitFormList[submitItem].year == this.viewSubmitFormList[viewItem].year) {
                this.submitFormList[submitItem] = this.deepClone(this.viewSubmitFormList[viewItem].submitList[0]);
                break;
              }
            }
          }
          return this.submitFormList;
        } else if (this.$route.query.submitPeriod == '2') { //季报
          for (let submitItem in this.submitFormList) {
            for (let viewItem in this.viewSubmitFormList) {
              if (this.submitFormList[submitItem].year == this.viewSubmitFormList[viewItem].year) {
                for (let item in this.viewSubmitFormList[viewItem].submitList) {
                  if (this.viewSubmitFormList[viewItem].submitList[item].quarter == this.submitFormList[submitItem].quarter) {
                    this.submitFormList[submitItem] = this.deepClone(this.viewSubmitFormList[viewItem].submitList[item]);
                    break;
                  }
                }
              }
            }
          }
          return this.submitFormList;
        } else if (this.$route.query.submitPeriod == '3') { //月报
          for (let submitItem in this.submitFormList) {
            for (let viewItem in this.viewSubmitFormList) {
              if (this.submitFormList[submitItem].year == this.viewSubmitFormList[viewItem].year) {
                for (let item in this.viewSubmitFormList[viewItem].submitList) {
                  if (this.viewSubmitFormList[viewItem].submitList[item].month == this.submitFormList[submitItem].month) {
                    this.submitFormList[submitItem] = this.deepClone(this.viewSubmitFormList[viewItem].submitList[item]);
                    break;
                  }
                }
              }
            }
          }
          return this.submitFormList;
        }

      },
      goBack() {
        this.$router.go(-1);
      },
      async putSubmitFormList() {
        let startDateInt = Number(this.$route.query.startDate);
        let endDateInt = Number(this.$route.query.endDate);
        if (this.$route.query.type == '1') { //指标要提交的表单
          let records = await this.getOldTargetListYear();

          if (this.$route.query.submitPeriod == '1') { //年报
            for (let item = startDateInt; item <= endDateInt; item++) {

              //提交表单的处理
              let form = this.deepClone(this.targetForm);
              form.ditemId = this.$route.query.id;
              form.year = item.toString();
              this.submitFormList.push(form);

              //表单显示的处理
              let viewSubmit = Object.assign({
                year: item.toString(),
                submitList: []
              });

              for (let recordsItem in records) {
                if (records[recordsItem].year == item.toString()) {
                  viewSubmit.submitList.push(records[recordsItem]);
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          } else if (this.$route.query.submitPeriod == '2') {//季报
            for (let item = startDateInt; item <= endDateInt; item++) {
              let viewSubmit = Object.assign({
                year: '',
                submitList: []
              });
              for (let quarter = 1; quarter <= 4; quarter++) {//季度循环
                let form = this.deepClone(this.targetForm);
                form.ditemId = this.$route.query.id;
                form.year = item.toString();
                form.quarter = quarter.toString();
                this.submitFormList.push(form);

                viewSubmit.year = item.toString();
                for (let recordsItem in records) {
                  if (records[recordsItem].year == item.toString() && records[recordsItem].quarter == quarter.toString()) {
                    viewSubmit.submitList.push(records[recordsItem]);
                  }
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          } else if (this.$route.query.submitPeriod == '3') {//月报
            for (let item = startDateInt; item <= endDateInt; item++) {
              let viewSubmit = Object.assign({
                year: '',
                submitList: []
              });
              for (let month = 1; month <= 12; month++) {//月份循环
                let form = this.deepClone(this.targetForm);
                form.ditemId = this.$route.query.id;
                form.year = item.toString();
                form.month = month;
                this.submitFormList.push(form);

                viewSubmit.year = item.toString();
                for (let recordsItem in records) {
                  if (records[recordsItem].year == item.toString() && records[recordsItem].month == month) {
                    viewSubmit.submitList.push(records[recordsItem]);
                  }
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          }
        } else if (this.$route.query.type == '2' || this.$route.query.type == '3') {  //任务或项目要提交的表单
          let records = [];
          if (this.$route.query.type == '2') {
            records = await this.getOldTaskListYear();
          } else if (this.$route.query.type == '3') {
            records = await this.getOldProjectListYear();
          }

          if (this.$route.query.submitPeriod == '1') { //年报
            for (let item = startDateInt; item <= endDateInt; item++) {
              let form = this.deepClone(this.taskForm);
              form.ditemId = this.$route.query.id;
              form.year = item.toString();
              this.submitFormList.push(form);
              //放入list中便于显示的遍历
              let viewSubmit = Object.assign({
                year: item.toString(),
                submitList: []
              });
              for (let recordsItem in records) {
                if (records[recordsItem].year == item.toString()) {
                  viewSubmit.submitList.push(records[recordsItem]);
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          } else if (this.$route.query.submitPeriod == '2') {//季报
            for (let item = startDateInt; item <= endDateInt; item++) {
              let viewSubmit = Object.assign({
                year: '',
                submitList: []
              });
              for (let quarter = 1; quarter <= 4; quarter++) {//季度循环
                let form = this.deepClone(this.taskForm);
                form.ditemId = this.$route.query.id;
                form.year = item.toString();
                form.quarter = quarter.toString();
                this.submitFormList.push(form);

                viewSubmit.year = item.toString();
                for (let recordsItem in records) {
                  if (records[recordsItem].year == item.toString() && records[recordsItem].quarter == quarter.toString()) {
                    viewSubmit.submitList.push(records[recordsItem]);
                  }
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          } else if (this.$route.query.submitPeriod == '3') {//月报
            for (let item = startDateInt; item <= endDateInt; item++) {
              let viewSubmit = Object.assign({
                year: '',
                submitList: []
              });
              for (let month = 1; month <= 12; month++) {//月份循环
                let form = this.deepClone(this.taskForm);
                form.ditemId = this.$route.query.id;
                form.year = item.toString();
                form.month = month;
                this.submitFormList.push(form);

                viewSubmit.year = item.toString();
                for (let recordsItem in records) {
                  if (records[recordsItem].year == item.toString() && records[recordsItem].month == month) {
                    viewSubmit.submitList.push(records[recordsItem]);
                  }
                }
              }
              this.viewSubmitFormList.push(viewSubmit);
            }
          }
        }
      },
      async getOldTargetListYear() {  //指标的表单数据
        return new Promise((resolve, reject) => {
          getOldTargetList(this.$route.query.id).then(response => {
            if (response.data.code == 0) {
              resolve(response.data.data)
            }
          })
        })

      },
      async getOldTaskListYear() {  //任务的表单数据
        return new Promise((resolve, reject) => {
          getOldTaskList(this.$route.query.id).then(response => {
            if (response.data.code == 0) {
              resolve(response.data.data)
            }
          })
        })

      },
      async getOldProjectListYear() {  //项目的表单数据
        return new Promise((resolve, reject) => {
          getOldProjectList(this.$route.query.id).then(response => {
            if (response.data.code == 0) {
              resolve(response.data.data)
            }
          })
        })

      },
      putHistory() {
        if (this.$route.query.type == '1') {  //获取指标历史进度上报数据
          getReportProgressHisTarget(this.$route.query.id).then(async response => {
            let records = await response.data.data;
            this.dealRecords(records,'1');
          })
        } else if (this.$route.query.type == '2') {//获取任务历史进度上报数据
          getReportProgressHisTask(this.$route.query.id).then(async response => {
            let records = await response.data.data;
            this.dealRecords(records,'2');
          })
        } else if (this.$route.query.type == '3') {//获取项目历史进度上报数据
          getReportProgressHisProject(this.$route.query.id).then(async response => {
            let records = await response.data.data;
            this.dealRecords(records,'3');
          })
        }
      },
      dealRecords(records,type) {
        if (records != null && records.length != 0) {
          for (let item in records) {
            let startDate = Number(records[item].startDate);
            let endDate = Number(records[item].endDate);
            let listData = [];
            if(type=='1'){
              listData = records[item].progressTargetVOList;
            }else if(type=='2'){
              listData = records[item].progressTaskVOList;
            }else if(type=='3'){
              listData = records[item].progressProjectVOList;
            }
            let reportObject = {
              type: null,
              viewSubmitFormList: [],
            };
            if (listData.length != 0) {
              if (listData[0].period == '1') {  //年报
                reportObject.type = '1';
                for (let yearItem = startDate; yearItem <= endDate; yearItem++) {
                  //放入list中便于显示的遍历
                  let viewSubmit = Object.assign({
                    year: yearItem.toString(),
                    submitList: []
                  });
                  for (let progressItem in listData) {
                    if (listData[progressItem].year == yearItem.toString()) {
                      viewSubmit.submitList.push(listData[progressItem]);
                    }
                  }
                  reportObject.viewSubmitFormList.push(viewSubmit);
                }
              } else if (listData[0].period == '2') {  //季报
                reportObject.type = '2';
                for (let yearItem = startDate; yearItem <= endDate; yearItem++) {
                  //放入list中便于显示的遍历
                  let viewSubmit = Object.assign({
                    year: yearItem.toString(),
                    submitList: []
                  });
                  for (let quarter = 1; quarter <= 4; quarter++) {
                    for (let progressItem in listData) {
                      if (listData[progressItem].year == yearItem.toString() && listData[progressItem].quarter == quarter.toString()) {
                        viewSubmit.submitList.push(listData[progressItem]);
                      }
                    }
                  }
                  reportObject.viewSubmitFormList.push(viewSubmit);
                }
              } else if (listData[0].period == '3') {  //月报
                reportObject.type = '3';
                for (let yearItem = startDate; yearItem <= endDate; yearItem++) {
                  //放入list中便于显示的遍历
                  let viewSubmit = Object.assign({
                    year: yearItem.toString(),
                    submitList: []
                  });
                  for (let month = 1; month <= 12; month++) {
                    for (let progressItem in listData) {
                      if (listData[progressItem].year == yearItem.toString() && listData[progressItem].month == month) {
                        viewSubmit.submitList.push(listData[progressItem]);
                      }
                    }
                  }
                  reportObject.viewSubmitFormList.push(viewSubmit);
                }
              }
              this.historyList.push(reportObject)
            }
          }
        }
      },
      selectArea(year, quarter, month, period) {
        this.yearTemp = year;
        this.quarterTemp = quarter;
        this.monthTemp = month;
        this.periodTemp = period;

        this.areaSelectVisible = true;
      },
      getAreaInfo(fullName, areaCode) {
        this.dealViewSubmitFormList(fullName, areaCode);
        this.areaSelectVisible = false;
      },
      cancelGetArea() {
        this.areaSelectVisible = false;
      },
      dealViewSubmitFormList(fullName, areaCode) {
        for (let viewItem in this.viewSubmitFormList) {
          if (this.viewSubmitFormList[viewItem].year == this.yearTemp) {
            if (this.periodTemp=='1') {  //年报
              this.viewSubmitFormList[viewItem].submitList[0].areaName = fullName;
              this.viewSubmitFormList[viewItem].submitList[0].areaCode = areaCode;
            }else if(this.periodTemp=='2'){  //季报
              for (let submitItem in this.viewSubmitFormList[viewItem].submitList) {
                if(this.viewSubmitFormList[viewItem].submitList[submitItem].quarter == this.quarterTemp){
                  this.viewSubmitFormList[viewItem].submitList[submitItem].areaName = fullName;
                  this.viewSubmitFormList[viewItem].submitList[submitItem].areaCode = areaCode;
                }
              }
            }else if(this.periodTemp=='3'){  //月报
              for (let submitItem in this.viewSubmitFormList[viewItem].submitList) {
                if(this.viewSubmitFormList[viewItem].submitList[submitItem].month == this.monthTemp){
                  this.viewSubmitFormList[viewItem].submitList[submitItem].areaName = fullName;
                  this.viewSubmitFormList[viewItem].submitList[submitItem].areaCode = areaCode;
                }
              }
            }

          }
        }
      },
      exportProgressFile(){
        this.$confirm("确定要导出进度信息吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          exportProgressFile(this.$route.query.id).then(response => {
            let exportFileName = "关于"+this.$route.query.itemName+"分解项的进度信息.docx";
            this.download(response.data, exportFileName)
          });
        })
      },
      // 下载文件
      download(data, filename) {
        if (data == null) {

        } else {
          let url = window.URL.createObjectURL(new Blob([data]));
          let link = document.createElement('a');
          link.style.display = 'none';
          link.href = url;
          link.setAttribute('download', filename);
          document.body.appendChild(link);
          link.click()
        }
      },



    }
  }
</script>

<style lang="scss" scoped>
  /deep/ .textarea textarea {
    height: 80px !important;
  }

  /deep/ .upload-demo {
    padding-top: 10px
  }

  .relateddiv {
    margin-left: 0
  }

  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }

  .bs-table_td {
    font-size: 16px;
    padding: 4px;
  }
  /deep/.el-input__inner {
    /*border-bottom-style: 1px solid red;*/
    border-right-style: none;
    border-top-style: none;
    border-left-style: none;
    /*border-bottom-style: 1px solid red;*/
    background-color: #FFF;
    background-image: none;
    border-radius: 0;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
  }
  /deep/.el-textarea__inner {
    border:none;
    display: block;
    resize: vertical;
    padding: 5px 15px;
    line-height: 1.5;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 100%;
    font-size: inherit;
    color: #606266;
    background-color: #FFF;
    background-image: none;
    -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  }
  /deep/.el-button--info.is-plain {
    color: #ffffff;
    background: #2077be;
    border-color: #2077be;
    margin-bottom: 5px;
  }
</style>
